package service

import (
	"errors"
	"github.com/wonderivan/logger"
	"k8s-plantform/config"
	"k8s-plantform/utils"
)

var Login login

type login struct{}

// 验证账号密码
func (l *login) Auth(username, password string) (token string, err error) {
	if username == config.AdminUser && password == config.AdminPwd {
		token, err = utils.JWTToken.GenToken(username, password)
		if err != nil {
			logger.Error("生成token失败")
			return "", errors.New("生成token失败")
		}
		return token, nil
	} else {
		logger.Error("登录失败, 用户名或密码错误")
		return "", errors.New("登录失败, 用户名或密码错误")
	}
}
